
from selenium import webdriver#支持网页脚本
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.common.action_chains import ActionChains

options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")  # 就是这一行告诉chrome去掉了webdriver痕迹，令navigator.webdriver=false，极其关键
# 还有其他options配置，此处和问题无关，略去
driver = webdriver.Chrome(options=options)
# driver = webdriver.Chrome()  # 或者其他浏览器
url0="https://we.51job.com/api/job/search-pc?api_key=51job&timestamp=1719364739&keyword=Qt&searchType=2&function=&industry=&jobArea=000000&jobArea2=&landmark=&metro=&salary=&workYear=&degree=&companyType=&companySize=&jobType=&issueDate=&sortType=0&pageNum=1&requestId=&keywordType=&pageSize=20&source=1&accountId=&pageCode=sou%7Csou%7Csoulb"
driver.get(url0)
# # 加载动态内容
# WebDriverWait(driver, 20).until(
#     EC.presence_of_all_elements_located((By.CLASS_NAME, 'nc_1__scale_text'))
# )
time.sleep(5)
# 模拟滑块滑动：根据实际情况调整选择器和滑动函数
# slider = driver.find_elements_by_class_name('nc_1__scale_text')  # 假设滑块有一个ID为'slider_id'
slider = driver.find_element(By.ID, 'nc_1_n1z')

# driver.execute_script("arguments[0].scrollIntoView(true);", slider)
# time.sleep(9)
# 使用ActionChains模拟人的操作
actions = ActionChains(driver)
actions.click_and_hold(slider)  # 按住滑块
# 滑动滑块从左到右
print("滑动滑块从左到右 start")
# for i in range(1, 252):  # 假设滑动300px
#     actions.move_by_offset(1, 0).perform()  # 向右移动滑块
#     time.sleep(0.01)  # 暂停0.1秒，以模拟人的滑动速度
actions.move_by_offset(252, 0).perform()
time.sleep(2)
print("滑动滑块从左到右 end")
# 释放滑块
actions.release().perform()
response = []
response.append(driver.page_source)
print(response)

json0 = driver.find_element(By.TAG_NAME, 'pre').text
print(json0)

# 关闭WebDriver
driver.quit()
